package com.richinfo.buddy.common.utils;

import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

public class SpringBeanUtils {

    @SuppressWarnings("unchecked")
    public static <T> T getBean(String beanName) {
        return (T) SpringContextUtils.getApplicationContext().getBean(beanName);
    }

    public static <T> T getBean(Class<T> clz) {
        return SpringContextUtils.getApplicationContext().getBean(clz);
    }

    public static AutowireCapableBeanFactory getAutowireCapableBeanFactory() {
        return SpringContextUtils.getApplicationContext().getAutowireCapableBeanFactory();
    }

    public static ConfigurableListableBeanFactory getBeanFactory() {
        return SpringContextUtils.getApplicationContext().getBeanFactory();
    }

    public static void autowireBean(Object existingBean) {
        getAutowireCapableBeanFactory().autowireBean(existingBean);
    }
}
